package com.huike.web.controller.report;


import com.huike.report.domain.vo.TargetIndexVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }

    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){
        log.info("今天的所有数据");
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String now = format.format(date);
        return AjaxResult.success(reportService.getTodayInfo(now));
    }

    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime" )String endCreateTime){
        log.info("代办数据");
        return AjaxResult.success(reportService.getTodoInfo(beginCreateTime,endCreateTime));
    }

    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                      @RequestParam("endCreateTime" )String endCreateTime){
        List<TargetIndexVo> list= reportService.changesalesStatistics(beginCreateTime,endCreateTime);
        return AjaxResult.success(list);
    }

    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(@RequestParam("beginCreateTime") String beginCreateTime,
                                               @RequestParam("endCreateTime" )String endCreateTime){
        List<TargetIndexVo> list =  reportService.businessChangeStatistics(beginCreateTime,endCreateTime);
        return AjaxResult.success(list);
    }
}